<template>
    <div class="login-container">
      <el-form :model="user" ref="refForm" :rules="loginFormrules" class="login-form">
          <h2 class="login-title">短视频平台</h2>
        <el-form-item label="用户名" prop="username">
            <el-input v-model="user.username" ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="user.password" ></el-input>
        </el-form-item>
        <el-form-item style="text-align:center">
            <el-button type="primary" @click="submitForm('refForm')">登录</el-button>
            <el-button type="info">重置</el-button>
        </el-form-item>
      </el-form>
       
    </div>
</template>
<script>
export default {
    data () {
        return {
            user:{
                username:'admin',
                password:''
            },
            loginFormrules:{
                username:[
                    // 当鼠标失去焦点时验证，必填
                    {required:true,message:'用户名不能为空', trigger: 'blur'},
                    {min: 3, max: 10, message: '用户名3-10位', trigger: 'blur'}
                ],
                password:[
                    {required:true,message:'密码不能为空', trigger: 'blur'}
                   
                ]
            }
        }
    },
    methods: {
        submitForm(formName){
          window.console.log(formName);
           this.$refs[formName].validate(valid=>{
            //    window.console.log(valid);
            if(valid){
                // window.console.log();
                this.$axios.post('/user/checkUser',this.user).then(result=>{
                    let{data:res}=result;
                    if(res.mate.status!=200)return this.$message.error(res.mate.msg); 
                    this.$message.success(res.mate.msg);
                    // 跳转主页
                    this.$router.push('/main')
                })
            }else{
                this.$message('请完善信息');
                // 防止页面刷新
                return false
            }
           })
        }
    }
}
</script>
<style scoped>
   .login-container{
       position: absolute;
       width: 100%;
       height: 100%;
       background-color: rgb(247, 242, 175);
   }
   .login-form{
       width: 350px;
       margin: 100px auto;
       background-color: aquamarine;
       padding: 30px;
       border-radius: 20px;
   }
   .login-title{
       color:hotpink;
       text-align: center;
   }
</style>